<?php

namespace App\depository;

use App\Models\ManagePlayerModel;
use App\Models\SubAuthorityModel;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;

class ManagePlayerDep
{
    public $model;

    public function __construct(){
        $this->model = new ManagePlayerModel();
    }

    public function first($id){
        $res = $this->model->where('id',$id)->first();
        return $res;
    }

    public function countByTeamId($teamId){
        $res = $this->model->where('gh_id',$teamId)->count();
        return $res;
    }

    public function countOp($teamId){
        $resAuth = SubAuthorityModel::where('team_id',$teamId)->get()->pluck('steamid');

        $res = $this->model->where('gh_id',$teamId)->whereIn('steamid',$resAuth->toArray())->count();
        return $res;
    }

    public function firstBySteamid($steamid){
        $res = $this->model->where('steamid',$steamid)->first();
        return $res;
    }

    public function add($data){
        $res = $this->model->insert($data);
        return $res;
    }

    public function get_list($num){
        $res = $this->model->orderBy("id", "desc")->limit($num)->get();
        return $res;
    }

    public function list($teamId){
        $res = $this->model->where('gh_id',$teamId)->get();
        return $res;
    }

    public function del_by_gh_id($gh_id){
        return $this->model->where('gh_id', $gh_id)->delete();
    }
}
